#include <bits/stdc++.h>

using namespace std;
class Solution {
public:
    int countDigitOne(int n) {
        long long dig=1,high=n/10,cur=n%10,low=0,ans=0,nn=n;
        while(nn){
            if(cur==0){
                ans+=(dig*high);
            }else if(1==cur){
                ans+=(high*dig+low+1);
            }else{
                ans+=(high+1)*dig;
            }
            nn/=10;
            dig*=10;
            high=nn/10;
            cur=nn%10;
            low=n%dig;
        }
        return ans;
    }
};
class Solution2 {
public:
    int countDigitOne(int n) {
        int dig=1,high=n/10,cur=n%10,low=0,ans=0;
        while(cur!=0||high!=0){
            if(cur==0) ans+=(high*dig);
            else if(cur==1) ans+=(high*dig+low+1); //+1是因为还有0没算
            else ans+=(high+1)*dig;
            low+=cur*dig;
            cur=high%10;
            high/=10;
            dig*=10;
        }
        return ans;
    }
};


int main(){
    Solution s;
    cout << s.countDigitOne(1410065408)<<endl;



    return 0;
}